﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using Gallio.Framework;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using DotNetNuke.Tests.UI.WatiN.WatiNObjects;
using DotNetNuke.Tests.UI.WatiN.Utilities;

namespace DotNetNuke.Tests.UI.WatiN
{
    [TestFixture]
    public class LoginTests : TestBase
    {
        WatiNBase baseWatinObject;
        IE ieInstance;

        [SetUp]
        public void SetUp()
        {
            IISManager.KillW3WP();
            DatabaseManager.DropDatabase(TestEnvironment.DatabaseName);
            DatabaseManager.CopyAndAttachDatabase(TestContext, TestEnvironment.DatabasePath, TestEnvironment.DatabaseName);

            // Open a new Internet Explorer window and navigate to the website
            ieInstance = WatiNUtil.OpenIEInstance(SiteURL, SilentMode, IETimeOut, AutoCloseIE);
            baseWatinObject = new WatiNBase(ieInstance, SiteURL);
        }

        [TearDown]
        public void TearDown()
        {
            DatabaseManager.DropDatabase(TestEnvironment.DatabaseName);
            WatiNUtil.CloseIEInstance(ieInstance);
        }

        [Test]
        [Row("host", "dnnhost", "SuperUser Account")]
        //[Row("admin", "dnnadmin", "Administrator Account")]
        public void Login_Is_Successful_With_Valid_Credentials(string name, string password, string displayName)
        {
            //Arrange
            VideoEnabled = true;
            StartAutoVideoCapture("LoginIsSuccesful", "Login Successful", TriggerEvent.TestFinished);
            LoginPage loginPage = new LoginPage(baseWatinObject);

            //Act
            loginPage.LoginUser(name, password);

            //Assert
            WatiNAssert.ContentEquals<Link>(displayName, baseWatinObject.RegisterLink);
        }

        [Test]
        [Row("host1", "dnnhost1")]
        [Row("admin1", "dnnadmin1")]
        [Row("test", "test")]
        public void Login_Fails_With_Invalid_Credentials(string name, string password)
        {
            //Arrange
            LoginPage loginPage = new LoginPage(baseWatinObject);

            //Act
            loginPage.LoginUser(name, password);

            //Assert
            WatiNAssert.ElementExists<Span>(loginPage.LoginMessage);
        }

    }
}
